﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using NLite.Collections;
using NLite.Internal;
using NLite.Collections.Internal;

namespace NLite.Messaging.Internal
{
    class Subject :BooleanDisposable, ISubject
    {
        
        public string Name { get; set; }
        public ISubscriber Subscriber { get; set; }
        public IExecutor Executor { get; set; }
        public IQueue<KeyValuePair<object, IMessage>> Queue { get; set; }


        public void Publish(object sender, IMessage message)
        {
            CheckNotDisposed();

            var pair = new KeyValuePair<object, IMessage>(sender, message);
            Queue.Enqueue(pair);

            Executor.Execute();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                Queue.Dispose();
                Subscriber.Clear();
            }
        }

       
    }
  
}
